﻿using System;
using System.Collections.Generic;
using Ext.Net;
using BLL;
using Model;
using System.Xml;
using System.Xml.Xsl;

namespace Web.View.d90_jfxxMenu
{
    public partial class Default : UIPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        //绑定Grid
        protected void d90_jfxx_DataBind(object sender, StoreRefreshDataEventArgs e)
        {
            d90_jfxxMgr mgr = new d90_jfxxMgr();
            e.Total = int.Parse(mgr.GetRecordCount_d90_jfxx(e.Parameters[d90_jfxx_Filter.ParamPrefix]));
            IList<d90_jfxx> list = mgr.FindAllByPage_d90_jfxx(e.Start.ToString(), e.Limit.ToString(), e.Parameters[d90_jfxx_Filter.ParamPrefix]);
            d90_jfxx_MainStore.DataSource = list;
            d90_jfxx_MainStore.DataBind();
        }
        //删除数据
        protected void BtnDel_Click(object sender, DirectEventArgs e)
        {
            d90_jfxxMgr mgr = new d90_jfxxMgr();
            RowSelectionModel sm = d90_jfxx_Grid.SelectionModel.Primary as RowSelectionModel;
            foreach (SelectedRow row in sm.SelectedRows)
            {
                d90_jfxx _d90_jfxx = new d90_jfxx();
                _d90_jfxx.rowid = int.Parse(row.RecordID);
                if (mgr.Del_d90_jfxx(_d90_jfxx))
                {
                    log.Debug("d90_jfxx中执行了删除，并成功");
                    X.Msg.Notify("成功", "<font color='green'>已经成功删除选中的记录</font>").Show();
                }
                else
                    X.Msg.Notify("失败", "<font color='green'>删除记录失败，请您重试！</font>").Show();
            }
            d90_jfxx_Grid.Reload();
        }
        protected void BtnSave_Click(object sender, DirectEventArgs e)
        {
            d90_jfxxMgr mgr = new d90_jfxxMgr();
            d90_jfxx _d90_jfxx = new d90_jfxx();
            if (Hid.Text.Length > 0)
                _d90_jfxx = mgr.FindById_d90_jfxx(int.Parse(Hid.Text));
            
			_d90_jfxx.jtbm = Txtjtbm.Text.Trim();
			_d90_jfxx.dzbm = Txtdzbm.Text.Trim();
			_d90_jfxx.hbh = Txthbh.Text.Trim();
			_d90_jfxx.rbh = Txtrbh.Text.Trim();
			_d90_jfxx.hzxm = Txthzxm.Text.Trim();
			_d90_jfxx.hzxb = Txthzxb.Text.Trim();
			_d90_jfxx.sfzh = Txtsfzh.Text.Trim();
			_d90_jfxx.zbh = Txtzbh.Text.Trim();
			_d90_jfxx.cbh = Txtcbh.Text.Trim();
			_d90_jfxx.txdz = Txttxdz.Text.Trim();
			_d90_jfxx.yzbm = Txtyzbm.Text.Trim();
			_d90_jfxx.dhhm = Txtdhhm.Text.Trim();
			_d90_jfxx.jtrs = Txtjtrs.Text.Trim();
			_d90_jfxx.nyrs = int.Parse(TxtNumnyrs.Text.Trim());
			_d90_jfxx.ssdq = Txtssdq.Text.Trim();
			_d90_jfxx.chsx = Txtchsx.Text.Trim();
			_d90_jfxx.hsx = Txthsx.Text.Trim();
			_d90_jfxx.jzjb = Txtjzjb.Text.Trim();
			_d90_jfxx.rcbz = Txtrcbz.Text.Trim();
			_d90_jfxx.rcsj = Txtrcsj.Text.Trim();
			_d90_jfxx.rcyy = Txtrcyy.Text.Trim();
			_d90_jfxx.jhje = Txtjhje.Text.Trim();
			_d90_jfxx.syje = Txtsyje.Text.Trim();
			_d90_jfxx.sfrq = Txtsfrq.Text.Trim();
			_d90_jfxx.sfxm = Txtsfxm.Text.Trim();
			_d90_jfxx.xmid = Txtxmid.Text.Trim();
			_d90_jfxx.fphm = Txtfphm.Text.Trim();
			_d90_jfxx.sfry = Txtsfry.Text.Trim();
			_d90_jfxx.zfry = Txtzfry.Text.Trim();
			_d90_jfxx.sfbz = int.Parse(TxtNumsfbz.Text.Trim());
			_d90_jfxx.sfdj = Txtsfdj.Text.Trim();

            bool isok = false;
            if (Hid.Text.Length > 0)
                isok = mgr.Update_d90_jfxx(_d90_jfxx);
            else
                isok = mgr.Add_d90_jfxx(_d90_jfxx);
            if (isok)
            {
                d90_jfxx_Win.Hide();
                X.Msg.Notify("成功", "<font color='green'>恭喜您，操作成功！</font>").Show();
                log.Debug("d90_jfxx中执行了保存（插入或修改），并成功");
                d90_jfxx_Grid.Reload();
            }
            else
                X.Msg.Notify("失败", "<font color='red'>操作失败，请您重试！</font>").Show();
        }
        //数据保存为Excel
        protected void BtnSaveToExcel(object sender, EventArgs e)
        {
            string json = ExcelGridData.Value.ToString();
            StoreSubmitDataEventArgs eSubmit = new StoreSubmitDataEventArgs(json, null);
            XmlNode xml = eSubmit.Xml;
            this.Response.Clear();
            this.Response.ContentType = "application/vnd.ms-excel";
            this.Response.AddHeader("Content-Disposition", "attachment; filename=QiDian10Excel.xls");
            XslCompiledTransform xtExcel = new XslCompiledTransform();
            xtExcel.Load(Server.MapPath("/View/ExcelTemp/Excel.xsl"));
            xtExcel.Transform(xml, null, this.Response.OutputStream);
            this.Response.End();

        }
    }
}